package com.wufei.tastefor.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wufei.tastefor.R;
import com.wufei.tastefor.bean.Special;

import java.util.List;

/**
 * Created by wbcomputer on 2015/11/11.
 */
public class SpecialAdapter extends AppBaseAdapter<Special> {
    String s = "classify_";
    Class<R.mipmap> cls;
    int value;


    public SpecialAdapter(List<Special> list, Context context) {
        super(list, context);
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        Special special = list.get(position);
        ViewHolder holder = ViewHolder.get(context,convertView,parent, R.layout.item_home_hot_grid);
        ImageView imageView = (ImageView) holder.findViewById(R.id.hot_grid_icon);
        TextView textView = (TextView) holder.findViewById(R.id.hot_grid_text);

        textView.setText(special.getSpecialName());

        cls = R.mipmap.class;
        try {
            value = cls.getDeclaredField(s+special.getSpecialId()).getInt(null);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                value = cls.getDeclaredField(s+special.getSpecialPicId()).getInt(null);
            } catch (IllegalAccessException e1) {
                e1.printStackTrace();
            } catch (NoSuchFieldException e1) {
                e1.printStackTrace();
            }
        }
        imageView.setImageResource(value);


        return holder;
    }


}
